from python_baway.common.xcommon import sep


class MyClass:
    '''
    A simple example class.
    '''
    i = 12345

    def f(self):
        '''
        A simple method of MyClass.

        :return: A string.
        '''
        return 'Hello World!' + str(self.i)


def myclass_static_method(name='Peter'):
    return 'Hello World! ' + str(name)


MyClass.static_method = myclass_static_method
del myclass_static_method


obj = MyClass()
print('obj.f():', obj.f())
print('MyClass.f(obj):', MyClass.f(obj))
print('obj.f:', repr(obj.f))
print('MyClass.f:', repr(MyClass.f))
print(MyClass.static_method())
print('MyClass.i:', MyClass.i)
print('MyClass.static_method:', MyClass.static_method)

sep(label='class doc:')
print(MyClass.__doc__)
sep(label='method doc:')
print(MyClass.f.__doc__)


class Complex:
    def __init__(self, real, imag=0):
        self.real = real
        self.imag = imag
        self.value = real + imag


def print_num_and_its_square(n):
    print(repr(n), repr(n ** 2))


sep()
xcom1 = Complex(1)
print(repr(xcom1))
print_num_and_its_square(xcom1.value)

xcom2 = Complex(0, 1j)
print(repr(xcom2))
print_num_and_its_square(xcom2.value)
